# import numpy as np
#
# a = np.array([[1, 2, 3],
#               [4, 5, 6],
#               [7, 8, 9]])
#
# target_element = a[1, 1]
# first_row = a[0]
# last_column = a[:, -1]
#
#
# print("原始2维数组a：")
# print(a)
# print("\n第1行第1列的元素：", target_element)
# print("第一行的所有元素：", first_row)
# print("最后一列的所有元素：", last_column)


# import numpy as np
#
# a = np.random.uniform(low=0.0, high=10.0, size=(2, 2))
#
# b = np.random.uniform(low=1.0, high=5.0, size=(2, 2))
#
# c = np.multiply(a, b)
#
# c_floor = np.floor(c)
#
# print("原始数组a：")
# print(a)
# print("\n原始数组b：")
# print(b)
# print("\na与b逐元素乘法结果c：")
# print(c)
# print("\nc向下取整结果（np.floor()）：")
# print(c_floor)




# import numpy as np
#
#
# a = np.array([[[1, 2],   # 深度0：第0个2行2列矩阵
#                [3, 4]],
#               [[5, 6],   # 深度1：第1个2行2列矩阵
#                [7, 8]]])
#
# print("原始3维数组a的形状：", a.shape)
# print("原始3维数组a：")
# print(a)
#
#
# b = np.ravel(a)
#
# print("\n展平后的1维数组b的形状：", b.shape)
# print("展平后的1维数组b：", b)





# import numpy as np
#
# a = np.arange(24).reshape(2, 3, 4)
#
# print("原始3维数组a的形状：", a.shape)  # 输出(2, 3, 4)
# print("原始3维数组a：")
# print(a)
#
# a_trans = np.transpose(a, axes=(2, 1, 0))
#
# print("\n轴对换后数组a_trans的形状：", a_trans.shape)
# print("轴对换后数组a_trans：")
# print(a_trans)

#


# import torch
# import numpy as np
#
#
# tensor1 = torch.tensor([[1.1, 2.2, 3.3],
#                         [4.4, 5.5, 6.6]])
# print("\n方法1（torch.tensor()）：")
# print("Tensor内容：", tensor1)
# print("Tensor形状：", tensor1.shape)
# print("Tensor数据类型：", tensor1.dtype)
#
# np_arr = np.array([7, 8, 9, 10])
#
# tensor2 = torch.from_numpy(np_arr)
# print("\n方法2（torch.from_numpy()）：")
# print("Tensor内容：", tensor2)
# print("Tensor形状：", tensor2.shape)
# print("Tensor数据类型：", tensor2.dtype)
#
# tensor3 = torch.ones(size=(3, 2), dtype=torch.float32)
# print("\n方法3（torch.ones()）：")
# print("Tensor内容：", tensor3)
# print("Tensor形状：", tensor3.shape)
# print("Tensor数据类型：", tensor3.dtype)
# #
#
# import numpy as np
#
# a = np.arange(24).reshape(2, 3, 4)
#
# print("原始3维数组a的形状：", a.shape)  # 输出(2, 3, 4)
# print("原始3维数组a：")
# print(a)
#
# a_trans = np.transpose(a, axes=(2, 1, 0))
#
# print("\n轴对换后数组a_trans的形状：", a_trans.shape)
# print("轴对换后数组a_trans：")
# print(a_trans)





# import torch
#
# a = torch.arange(9)
# print("原始1维Tensor a：")
# print("内容：", a)
# print("形状：", a.shape)
#
# a_view = a.view(3, 3)
# a_view[0, 0] = 999
# print("\n1. view(3,3)后的Tensor a_view：")
# print("内容：", a_view)
# print("形状：", a_view.shape)
# print("修改a_view后，原Tensor a的内容：", a)
#
# a_reshape = a.reshape(1, 3, 3)
# print("\n2. reshape(1,3,3)后的Tensor a_reshape：")
# print("内容：", a_reshape)
# print("形状：", a_reshape.shape)
#
# a.resize_(5, 2)
# print("\n3. resize_(5,2)后的原Tensor a：")
# print("内容：", a)
# print("形状：", a.shape)
#



# import torch
#
# a = torch.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
# print("原始Tensor a：", a)
#
# a_sigmoid = torch.sigmoid(a)
#
# print("Sigmoid激活后的Tensor a_sigmoid：", a_sigmoid)



import torch

a = torch.randint(low=0, high=11, size=(2, 4))
print("原始2维Tensor a：")
print("内容：", a)
print("形状：", a.shape)

top2_values, top2_indices = torch.topk(a, k=2, dim=1)

print("\n每行最大的2个值（top2_values）：")
print(top2_values)
print("\n每行最大2个值的列索引（top2_indices）：")
print(top2_indices)